package top.haijunit.springboot.bucket.springsecurity02.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import top.haijunit.mark.common.mybatis.base.BaseEntity;

import java.util.Collection;

/**
 * @Author 百旺张
 * @Date 2021/11/9
 * @Description
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("tb_user")
@ApiModel(value = "User对象", description = "用户表")
public class UserEntity extends BaseEntity implements UserDetails {

    @TableId(value = "tb_id", type = IdType.AUTO)
    @ApiModelProperty("用户Id")
    private Integer userId;

    @ApiModelProperty("账号")
    private String username;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("姓名")
    private String nickname;

    @ApiModelProperty("邮箱地址")
    private String email;

    @ApiModelProperty("联系电话")
    private String phone;

    @ApiModelProperty("用户头像")
    private String salt;

    @ApiModelProperty("用户签名")
    private String token;

    @ApiModelProperty("数据状态")
    private Integer status;

    @ApiModelProperty("乐观锁")
    private Integer version;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // List<GrantedAuthority> list = AuthorityUtils.commaSeparatedStringToAuthorityList("role");
        return AuthorityUtils.createAuthorityList("admin", "user", "ROLE_manager", "ROLE_maintainer");
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
